import { Route } from "@ant-design/pro-layout/lib/typings";
import { Route as RouteItem } from "react-router-dom";
import IPageInterface from "../interface/pageInterface";
import CompanyManagePage from "../pages/company/manage";
import EquipmentConfigPage from "../pages/equipment/config";
import EquipmentPage from "../pages/equipment/manage";
import EquipmentRecordPage from "../pages/equipment/record";
import MemberManagePage from "../pages/member/manage";
import UserManagePage from "../pages/member/member";
import WorkOrderManagePage from "../pages/workOrder/mange";

export default class RouteUtil {

    static menus: IPageInterface<any>[] = [
        MemberManagePage,
        EquipmentPage,
        CompanyManagePage,
        WorkOrderManagePage,
        EquipmentRecordPage,
        EquipmentConfigPage,
        UserManagePage
    ];

    /**渲染到路由中去 */
    static renderToContent() {
        return RouteUtil.menus.map(p => {
            return (
                <RouteItem path={p.path} component={p.component} key={p.path} />
            );
        });
    }

    /**渲染左面的menu */
    static renderToMenu(): Route {
        const _route: Route = {
            path: "/",
            routes: []
        };
        this.menus.forEach(p => {
            const _routeInfo = {
                name: p.title,
                path: p.path,
            };
            if (p.group) {
                let _find: Route | undefined = _route.routes!.find(sp => sp.name === p.group);
                if (!_find) {
                    _find = { name: p.group, routes: [], path: p.path + "/group" };
                    _route.routes?.push(_find);
                }
                _find!.routes!.push(_routeInfo)
            }
            else {
                _route.routes?.push(_routeInfo)
            }
        })
        return _route;
    }
}